﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="sooritakanne_vmemaettevote", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(SooritakanneVmemaettevote))]
    public class SooritakanneVmemaettevoteSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected ISooritakanneVmemaettevote clazz;
        
        public SooritakanneVmemaettevoteSerializer(ISooritakanneVmemaettevote clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Arinimi!=null) {
                Writer.WriteStartElement("arinimi");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.ArinimiSeesytlevas!=null) {
                Writer.WriteStartElement("arinimi_seesytlevas");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ArinimiSeesytlevas))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OiguslikVorm!=null) {
                Writer.WriteStartElement("oiguslik_vorm");
                Writer.WriteTypeAttribute("http://producers.arireg.xtee.riik.ee/producer/arireg", "x_oigvorm");
                Writer.WriteString(clazz.OiguslikVorm.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.OiguslikuVormiMarkus!=null) {
                Writer.WriteStartElement("oigusliku_vormi_markus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OiguslikuVormiMarkus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Registrikood!=null) {
                Writer.WriteStartElement("registrikood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Registrikood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Asukoht!=null) {
                Writer.WriteStartElement("asukoht");
                global::Xtee.Core.SerializationMetadata metaAsukoht = this.GetMetaData(clazz.Asukoht);
                Writer.WriteTypeAttribute(metaAsukoht.TypeQualifiedName.Namespace, metaAsukoht.TypeQualifiedName.Name);
                metaAsukoht.NewSerializer(clazz.Asukoht).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.SeadusteAlusRiik!=null) {
                Writer.WriteStartElement("seaduste_alus_riik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SeadusteAlusRiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.TegutsemiseMaaMarkus!=null) {
                Writer.WriteStartElement("tegutsemise_maa_markus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TegutsemiseMaaMarkus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MajAruMarkus!=null) {
                Writer.WriteStartElement("maj_aru_markus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MajAruMarkus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Markused!=null) {
                Writer.WriteStartElement("markused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.Markused.Count);
                if (((clazz.Markused == null) 
                            || (clazz.Markused.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                }
                for (int x = 0; ((clazz.Markused != null) 
                            && (x < clazz.Markused.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("item");
                    if (clazz.Markused[x]!=null) {
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Markused[x]))).ToString());
                    }
                    else {
                        Writer.WriteAttributeString("xsi", "nil", null, "1");
                    }
                    Writer.WriteEndElement();
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            if (Reader.LocalName=="arinimi_seesytlevas") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>arinimi_seesytlevas");
                }
                clazz.ArinimiSeesytlevas = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi_seesytlevas")).Value;
            }
            if (Reader.LocalName=="oiguslik_vorm") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>oiguslik_vorm");
                }
                clazz.OiguslikVorm = new global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.XOigvorm(Reader.ReadElementString("oiguslik_vorm"));
            }
            if (Reader.LocalName=="oigusliku_vormi_markus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>oigusliku_vormi_markus");
                }
                clazz.OiguslikuVormiMarkus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("oigusliku_vormi_markus")).Value;
            }
            if (Reader.LocalName=="registrikood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>registrikood");
                }
                clazz.Registrikood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("registrikood")).Value;
            }
            if (Reader.LocalName=="asukoht") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>asukoht");
                }
                global::Xtee.Core.SerializationMetadata metaAsukoht = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressType>(Reader, "aadressType", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Asukoht = metaAsukoht.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IAadressType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("asukoht");
                    metaAsukoht.NewSerializer(clazz.Asukoht).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="seaduste_alus_riik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>seaduste_alus_riik");
                }
                clazz.SeadusteAlusRiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("seaduste_alus_riik")).Value;
            }
            if (Reader.LocalName=="tegutsemise_maa_markus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>tegutsemise_maa_markus");
                }
                clazz.TegutsemiseMaaMarkus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tegutsemise_maa_markus")).Value;
            }
            if (Reader.LocalName=="maj_aru_markus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>maj_aru_markus");
                }
                clazz.MajAruMarkus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("maj_aru_markus")).Value;
            }
            if (Reader.LocalName=="markused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>sooritakanne_vmemaettevote>markused");
                }
                clazz.Markused = new System.Collections.Generic.List<System.String>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("markused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.LocalName=="item") {
                            if ((Reader.IsElementNil() == false)) {
                                clazz.Markused.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                            }
                            else {
                                clazz.Markused.Add(null);
                                Reader.Skip();
                            }
                        }
                        else {
                            throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">item", Reader.LocalName);
                        }
                    }
                    if ((clazz.Markused.Count < 1m)) {
                        throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "item");
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
